package com.jingtai.shop.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingtai.common.template.ResultMapInfo;
import com.jingtai.core.entity.member.MemberCollectGoods;
import com.jingtai.shop.common.template.ShopBaseController;
import com.jingtai.shop.service.user.MemberCollectGoodsService;
import com.jingtai.shop.webfacade.bo.store.CollectGoodsBO;
import com.jingtai.shop.webfacade.bo.store.CollectGoodsListBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = "商城-收藏商品")
@RestController
@RequestMapping("/shop/collect")
@CrossOrigin(origins = "*")
public class CollectGoodsController extends ShopBaseController {

    @Resource
    private MemberCollectGoodsService goodsService;

    /**
     * 用户查看自己收藏的商品列表
     */
    @ApiOperation(value = "查看商品收藏列表")
    @PostMapping("/showCollectGoods")
    public Map<String, Object> showCollectGoods(CollectGoodsListBO bo) {
        bo.validate();
        Page<MemberCollectGoods> memberCollectGoodsPage = goodsService.showCollectGoods(getUserId(), bo.getGoodsTitle(), bo.getPageNo(), bo.getPageSize());
        return returnResultMap(ResultMapInfo.GETSUCCESS, memberCollectGoodsPage);
    }

    /**
     * 点击收藏/取消商品
     */
    @ApiOperation(value = "点击收藏/取消商品")
    @PostMapping("/collectGoods")
    public Map<String, Object> collectGoods(@RequestBody CollectGoodsBO bo) {
        bo.validate();
        boolean collectGoodsStatus = goodsService.collectGoods(bo.getGoodsCode(), getUserId(), bo.getCollectStatus());
        return returnResultMap(collectGoodsStatus ? ResultMapInfo.OPERATE_SUCCESS : ResultMapInfo.OPERATE_FAIL);
    }

}
